﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Data;
using WinnerCMS.Data;
using WinnerCMS.Common;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// BLL_Admin_FriendLink 的摘要说明。
    /// </summary>
    public class FriendLinkManage
    {
        private static readonly FriendLinkDal MyDAL = new FriendLinkDal();

        #region 添加\修改链接

        /// <summary>
        /// 添加\修改链接
        /// </summary>
        /// <param name="model"></param>
        /// <param name="UpdatePanel1"></param>
        public void Add(FriendLink model, UpdatePanel UpdatePanel1)
        {
            if (string.IsNullOrEmpty(model.Url))
            {
                MsgBox.Message("请输入网址！", UpdatePanel1);
            }
            else if (string.IsNullOrEmpty(model.Title))
            {
                MsgBox.Message("请输入网站名称！", UpdatePanel1);
            }
            else
            {
                model.Password = "";
                model.UpdateTime = DateTime.Now;
                if (model.Id == 0)
                {
                    MyDAL.Add(model);

                    Log logModel = new Log();
                    logModel.Type = "友情链接管理";
                    logModel.Event = "添加链接：" + model.Title;
                    LogManage.Add(logModel);

                    MsgBox.Message("添加成功！", "FriendLink.aspx", UpdatePanel1);
                }
                else
                {
                    MyDAL.Edit(model);

                    Log logModel = new Log();
                    logModel.Type = "友情链接管理";
                    logModel.Event = "修改链接：" + model.Title;
                    LogManage.Add(logModel);

                    MsgBox.Message("修改成功！", "FriendLink.aspx", UpdatePanel1);
                }
            }
        }

        #endregion

        /// <summary>
        /// 加载链接
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public FriendLink GetInfo(string ID)
        {
            return MyDAL.GetInfo(int.Parse(ID));
        }

        /// <summary>
        /// 删除链接
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="UpdatePanel1"></param>
        public void Delete(string ID, UpdatePanel UpdatePanel1)
        {
            MyDAL.Delete(int.Parse(ID));

            Log logModel = new Log();
            logModel.Type = "友情链接管理";
            logModel.Event = "添加链接" + ID;
            LogManage.Add(logModel);

            MsgBox.Message("删除成功！", UpdatePanel1);
        }

        /// <summary>
        /// 绑定友情链接--后台使用
        /// </summary>
        /// <param name="GV_List"></param>
        /// <returns></returns>
        public void BindList(BaseDataBoundControl GV_List)
        {
            GV_List.DataSource = MyDAL.BindList();
            GV_List.DataBind();
        }

        /// <summary>
        /// 绑定友情链接--前台使用
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="Pass"></param>
        /// <returns></returns>
        public IList<FriendLink> BindList(string Type, bool Pass)
        {
            return MyDAL.BindList(Type, Pass);
        }

        /// <summary>
        /// 链接排序
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        public void UpDown(string id, string type)
        {
            MyDAL.UpDown(id, type);

            Log logModel = new Log();
            logModel.Type = "友情链接管理";
            logModel.Event = "链接排序,ID=" + id;
            LogManage.Add(logModel);
        }
    }
}